package com.firepongo.chaos.app.service.init;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;

@Component
@Slf4j
public class InitAppCheckService {


    @Value("${app.ali.sms.access.key.id:}")
    private String aliSmsId;
    @Value("${app.ali.sms.access.key.secret:}")
    private String aliSmsSecret;
    @Value("${app.ali.sms.access.key.signName:}")
    private String aliSmsSignName;

    @Value("${app.tencent.sms.appid:}")
    private Integer tencentSmsAppid;
    @Value("${app.tencent.sms.appkey:}")
    private String tencentSmsAppkey;
    @Value("${app.tencent.sms.smsSign:}")
    private String tencentSmsSmsSign;

    @Value("${app.search.host:}")
    private String searchHost;

    public void check() {
        log.info("【Chaos】:App开始参数检查！");
        log(!StringUtils.isEmpty(aliSmsId) && !StringUtils.isEmpty(aliSmsSecret) && !StringUtils.isEmpty(aliSmsSignName), "阿里SMS服务已启用", "阿里SMS服务未启用");
        log(tencentSmsAppid != null && !StringUtils.isEmpty(tencentSmsAppkey), "腾讯SMS服务已启用", "腾讯SMS服务未启用");
        log.info("【Chaos】:App完成参数检查！");
    }

    private void log(boolean is, String yesLog, String noLog) {
        if (is) {
            log.info("【Chaos】:{}", yesLog);
        } else {
            log.warn("【Chaos】:{}", noLog);
        }
    }
}
